<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>编辑公告</title>
    <%@ include file="inc/css.jsp" %>
</head>
<body>

<div class="wrapper">
    <%@ include file="inc/nav.jsp" %>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">公告管理</h1>
                <h4 style="margin-left: 10px;">——编辑公告</h4>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <form class="form-horizontal nice-validator n-default" novalidate="novalidate">
                            <input type="hidden" id="placardId" value="${placard.id}"/>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">公告标题:</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="title" name="title" maxlength="20" value="${placard.title}" placeholder="请输入公告标题"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">公告详情:</label>
                                <div class="col-sm-8">
                                    <textarea cols="40" rows="8" class="form-control" style="resize: none" maxlength="2000" id="description" placeholder="请输入公告详情，最多2000个字">${placard.description}</textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">发送时间:</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control input-append date form_datetime" style="width: 180px;" readonly id="sendTime" name="sendTime" maxlength="20" value="${fn:substring(placard.sendTime, 0, 19)}" placeholder="请选择发送时间"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-10" style="text-align: center">
                                    <a href="javascript:void(0)" class="btn btn-success" role="button" onclick="_infoDetail.fn.subInfo()">保存</a>
                                    <a href="backend/placard/index" class="btn btn-primary" role="button">返回</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>
    <!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<%@ include file="inc/footer.jsp" %>
</body>
</html>
<script type="text/javascript">
    var _infoDetail = {
        v: {
            id: "_infoDetail",
            list: [],
            dTable: null
        },
        fn: {
            init: function () {
                $('.form_datetime').datetimepicker({
                    language: 'zh-CN',
                    weekStart: 1,
                    todayBtn: 1,
                    autoclose: 1,
                    todayHighlight: 1,
                    startView: 2,
                    forceParse: 0,
                    showMeridian: 1,
                    format: 'yyyy-mm-dd hh:ii:ss'
                });
            },
            checkData: function () {
                var flag = true;
                var title = $('#title').val();
                var description = $('#description').val();
                var sendTime = $('#sendTime').val();

                if (null == title || title == '') {
                    $sixmac.notify("请输入公告标题", "error");
                    flag = false;
                    return;
                }

                if (null == description || description == '') {
                    $sixmac.notify("请输入公告详情", "error");
                    flag = false;
                    return;
                }

                if (null == sendTime || sendTime == '') {
                    $sixmac.notify("请选择发送时间", "error");
                    flag = false;
                    return;
                }

                return flag;
            },
            subInfo: function () {
                // 所有的验证通过后，执行新增操作
                if (_infoDetail.fn.checkData()) {
                    $.post(_basePath + "backend/placard/save",
                            {
                                "id": $('#placardId').val(),
                                "title": $('#title').val(),
                                "description": $('#description').val(),
                                "sendTime": $('#sendTime').val()
                            },
                            function (data) {
                                if (data == 1) {
                                    window.location.href = _basePath + "backend/placard/index";
                                } else if (data == -1) {
                                    $sixmac.notify("请输入正确的发送时间", "error");
                                } else {
                                    $sixmac.notify("操作失败", "error");
                                }
                            });
                }
            }
        }
    }

    $(function () {
        _infoDetail.fn.init();
    });
</script>